package day13;

import java.io.*;
import java.util.ArrayList;

public class test7 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        User u1=new User("黄胜",22);
        User u2=new User("李胜",23);
        User u3=new User("刘胜",24);
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("study\\src\\java.txt"));
        ArrayList<User> list=new ArrayList<>();
        list.add(u1);
        list.add(u2);
        list.add(u3);
        oos.writeObject(list);
        oos.close();

        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("study\\src\\java.txt"));
       Object obj=ois.readObject();
        ArrayList<User> arraylist =(ArrayList<User>)obj;
        for (User user : arraylist) {
            System.out.println(user);
        }
       ois.close();



    }
}
